#!/bin/sh
#
# Copyright (C) 2000-2025 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Run a simple backup of the Bacula build directory
#   then restore it.
#
TestName="cloud-recycle-test"
JobName=backup

. scripts/functions

require_cloud

#config is required for cloud cleanup
scripts/copy-confs
scripts/cleanup

#
# Zap out any schedule in default conf file so that
#  it doesn't start during our test
#
outf="$tmp/sed_tmp"
echo "s%  Schedule =%# Schedule =%g" >${outf}
cp $scripts/bacula-dir.conf $tmp/1
sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf

change_jobname BackupClient1 $JobName
start_test

$bperl -e "add_attribute('$conf/bacula-sd.conf', 'MaximumPartSize', '50MB', 'Device')"

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
setdebug level=4 storage=File1
label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0
update volume=TestVolume001 actiononpurge=truncate
run job=$JobName level=Full yes
wait
run job=$JobName level=Full yes
status storage=File1
wait
messages
quit
END_OF_DATA

run_bacula

cat <<END_OF_DATA >$tmp/bconcmds
@$out $tmp/log1.out
setdebug level=4 storage=File1
purge volume=TestVolume001
run job=$JobName yes
wait
messages
cloud list storage=File1 volume=TestVolume001
@# 
@# now do a restore
@#
@$out $tmp/log2.out  
#setbandwidth client=$CLIENT limit="100 kb/s"
setdebug level=4 storage=File1
restore where=$tmp/bacula-restores select all done
yes
wait
messages
purge volume=TestVolume001
truncate volume=TestVolume001 pool=File storage=File1
cloud list storage=File1 volume=TestVolume001
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File1
stop_bacula

check_two_logs
end_test
